package com.llkj.qingnianguoxue.videoplayer.corver;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.kk.taurus.playerbase.player.OnTimerUpdateListener;
import com.kk.taurus.playerbase.receiver.BaseCover;
import com.kk.taurus.playerbase.receiver.ICover;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.util.PlayingTimeListener;

/**
 * 视频支付层
 */

public class PayCorver extends BaseCover implements OnTimerUpdateListener {

    private boolean mIsBuy = false;
    public PayCorver(Context context) {
        super(context);
    }
    private PlayingTimeListener playListener;

    @Override
    public void onReceiverBind() {
        super.onReceiverBind();
        setPayViewVisible(false);

    }
    @Override
    public void onTimerUpdate(int curr, int duration, int bufferPercentage) {
        Log.e("Log","====当前播放===="+curr);
        if(curr>=60*1000 && getView().getVisibility()== View.GONE && !mIsBuy){
            requestPause(null);
            setPayViewVisible(true);
            requestStopTimer();//这个控制计时暂停
        }
        if(playListener !=null){
            playListener.isPlay(curr);
        }
    }

    public void setPlayListener(PlayingTimeListener listener){
        playListener = listener;
    }

    @Override
    public void onPlayerEvent(int eventCode, Bundle bundle) {

    }

    @Override
    public void onErrorEvent(int eventCode, Bundle bundle) {

    }

    @Override
    public void onReceiverEvent(int eventCode, Bundle bundle) {

    }

    private void setPayViewVisible(boolean visible){
        setCoverVisibility(visible? View.VISIBLE: View.GONE);
    }

    @Override
    public View onCreateCoverView(Context context) {
        return View.inflate(context, R.layout.layout_video_look_at, null);
    }
    @Override
    public int getCoverLevel() {
        return ICover.COVER_LEVEL_MEDIUM;
    }

    public void isBuyVideo(boolean isBuy){
        mIsBuy = isBuy;
    }
}
